import time
import xlrd
from selenium.webdriver.common.by import By
from xlutils.copy import copy

import DBUtils
from selenium import webdriver

class Test_wangdai:
    book = copy(xlrd.open_workbook(filename="a.xls", encoding_override=True))
    time = time.strftime('%y年%m月%d日%H:%M:%S')

    def test_wangdai_success001(self):  # 网贷申请成功

        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90")
        element01 = driver.find_element(By.XPATH,
                                        '//input[@type="text" and @placeholder="请输入您的用户名" and @class="form-control"]')
        element01.send_keys("lisi")
        element02 = driver.find_element(By.XPATH, '//input[@type="password" and @placeholder="请输入密码" ]')
        element02.send_keys("123456")
        # 点击登录
        element03 = driver.find_element(By.XPATH, '//button[@id="login_btn" and @class="btn btn-block btn-primary"]')
        element03.click()
        # 点击金融工具
        element04 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a')
        element04.click()
        time.sleep(1)
        # 点击安全网贷
        element05 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a')
        element05.click()
        time.sleep(1)
        # 输入贷款金额
        element06 = driver.find_element(By.XPATH, '//*[@id="amount"]')
        element06.send_keys("10000")
        time.sleep(1)
        # 输入贷款期限
        element07 = driver.find_element(By.XPATH, '//*[@id="term"]')
        element07.send_keys("100")
        time.sleep(1)
        # 点击申请
        element08 = driver.find_element(By.XPATH, '//*[@id="submit"]')
        element08.click()
        time.sleep(1)
        # 点击确认
        element09 = driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]')
        element09.click()
        time.sleep(1)
        sql = "select * from loan where userId=1"
        if len(DBUtils.select(sql, [])) == 21:
            print("申请成功")
        else:
            print("申请失败")
        assert len(DBUtils.select(sql, [])) == 21
